<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="UTF-8"%>
<%
    String server = "http://images.139cm.com/jpdy/jpdymobile/";

	String sql = "  UPDATE  `t_appdown_num` "+
	             " SET `downnum` = `downnum`+1 "+
	             "  WHERE `appid` = ? ";
    
	String appId = request.getParameter("i");
	System.out.println("==================appId:"+appId);
	Connection conn = null;
	PreparedStatement pst = null;
	ResultSet rs = null;

	String downUrl = "";
	try {
		//连接数据库
		String drive = "com.mysql.jdbc.Driver";
		String url = "jdbc:mysql://127.0.0.1:3306/ecp";
		Class.forName(drive);
		DriverManager.setLoginTimeout(3);
		conn = DriverManager.getConnection(url, "root","qweasd");
		pst = conn.prepareStatement(sql);
        pst.setString(1,appId);
        pst.executeUpdate();
        
        //查询文件名称
        pst.close();
        sql = "  SELECT t.filename FROM t_appdown_num t WHERE t.appid = ? ";
        pst = conn.prepareStatement(sql);
        pst.setString(1,appId);
      //  downUrl = "http://images.139cm.com/jpdy/jpdymobile/"+appId+".apk";
	    rs = pst.executeQuery();
		if (rs.next()) {
			downUrl = server+ rs.getString("filename");
		}else{
		    downUrl = server+"wwww.apk";
		}
		} catch (Exception e) {
		     out.print("error");
		} finally {
		   if(rs!=null){
			 rs.close();
	       }
	       if(pst!=null){
			 pst.close();
		   }
		   if(conn!=null){
			 conn.close();
		   }
		}
	  response.sendRedirect(downUrl);
%>